package com.woniuxy.businessassembly.service.impl;

import com.woniuxy.businessassembly.dao.HotelPolicyMapper;
import com.woniuxy.businessassembly.dao.HotelSettleMapper;
import com.woniuxy.businessassembly.model.HotelInfo;
import com.woniuxy.businessassembly.dao.HotelInfoMapper;
import com.woniuxy.businessassembly.model.HotelSettle;
import com.woniuxy.businessassembly.service.IHotelInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Kevin Kwok
 * @since 2021-05-24
 */
@Service
@Transactional
public class HotelInfoServiceImpl extends ServiceImpl<HotelInfoMapper, HotelInfo> implements IHotelInfoService {
    @Resource
    private HotelInfoMapper hotelInfoMapper;
    @Resource
    private HotelSettleMapper settleMapper;
    @Resource
    private HotelPolicyMapper policyMapper;

    @Override
    public int addHotelInfo(HotelInfo hotelInfo) {
        //根据名字查询这个酒店是否已经审核通过，如果通过了新增酒店信息展示给大家看
        HotelSettle hotelSettle = settleMapper.queryCheckInfo(hotelInfo.getHotelName());
        Integer status = hotelSettle.getStatus();
        if(status==1){
            int i = hotelInfoMapper.addHotelInfo(hotelInfo);
        }
        return 0;
    }

    @Override
    public int modifyHotelInfo(HotelInfo hotelInfo) {
        /*根据酒店名查询酒店的id*/
        HotelInfo queried = policyMapper.queryByName(hotelInfo.getHotelName());
        hotelInfo.setHotelId(queried.getHotelId());
        int i = hotelInfoMapper.modifyHotelInfo(hotelInfo);
        return i;
    }

    @Override
    public HotelInfo queryHotelInfo(String hotelName) {
        HotelInfo hotelInfo = hotelInfoMapper.queryHotelInfo(hotelName);
        return hotelInfo;
    }

    @Override
    public List<HotelInfo> queryHotelInfoByType(Integer id) {
        List<HotelInfo> hotelInfos = hotelInfoMapper.queryHotelInfoByType(id);
        return hotelInfos;
    }

    @Override
    public int deleteInfoById(Integer id) {
        int i = hotelInfoMapper.deleteInfoById(id);
        return i;
    }
}
